var call_submit_back_flag = false; //是否数据提交之后回调函数
var myCodeFrom; //表单验证对象
$(function(){
	var getInfoObj=function(){
		return 	$(this).parents("dd").find('.info');
	}
	$("[datatype]").focusin(function(){
		if(this.timeout){clearTimeout(this.timeout);}
		var infoObj=getInfoObj.call(this);
		if(infoObj.siblings(".Validform_right").length!=0){
			return;	
		}
		infoObj.show().siblings().hide();
		
	}).focusout(function(){
		var infoObj=getInfoObj.call(this);
		this.timeout=setTimeout(function(){
			infoObj.hide().siblings(".Validform_wrong,.Validform_loading").show();
		},0);
		
	});
	myCodeFrom = $("form[name='myfromSubmit']").Validform({
		tiptype:4,
		ajaxPost:true,
		ignoreHidden:true,
		beforeSubmit:function(curform){
			swal({
				title: "",
				text: '<div class="sk-spinner sk-spinner-three-bounce"><div class="sk-bounce1"></div><div class="sk-bounce2"></div><div class="sk-bounce3"></div></div><br>正在努力请求...',
				html: true,
				showConfirmButton: false 
			});
		},
		callback:function(data){
			if(data.status == '1'){
				swal("", data.info, "success");
				if(call_submit_back_flag === true){
					call_submit_back_func(data); //回调函数
				}
				if( data.url != '') {
					setTimeout(function(){
						location.href = data.url;
					},1500);
				}
			}else if( data.info != null ) {
				swal("", data.info, "error");
			} else {
				swal("", "操作失败，请重新操作", "error");
			}
		}
	});
});

$(document).on( 'click' , '[menu="tip_menu"]',function(){
	var _self = $(this);
	var icon = _self.attr('icon');
	icon = icon ? icon : 'warning';
	swal({
		title: _self.attr('title'),
		type: icon,
		showCancelButton: true,
		confirmButtonColor: "#DD6B55",
		confirmButtonText: "确定",
		cancelButtonText:"取消",
		closeOnConfirm: false
	}, function() {
		//判断是否是ajax请求
		if( _self.attr('request_type') == 'ajax' ) {
			var load_text = _self.attr('load_txt');
			if( load_text == '' || load_text == undefined ) {
				load_text = '正在加载，请稍后...'
			}
			waitload( load_text );
			$.get(_self.attr('href'),function(data){
				if( data.status == 1 ) {
					swal({
						title: data.info,
						type: "success",
						showCancelButton: false,
						confirmButtonColor: "#DD6B55",
						confirmButtonText: "确定",
						closeOnConfirm: false
					} , function(){
						location.reload();
					});
				} else {
					swal("", data.info, "error");
				}
			},'json');
		} else {
			location.href = _self.attr( 'href' );
		}
	});
	return false;

});

function waitload( data ){
	swal({
		title: "",
		text: '<div class="sk-spinner sk-spinner-three-bounce"><div class="sk-bounce1"></div><div class="sk-bounce2"></div><div class="sk-bounce3"></div></div><br>'+data,
		html: true,
		showConfirmButton: false 
	});
}